package com.jy.adscm.wechat.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.wechat.bean.QueryWechatRepair;
import com.jy.adscm.wechat.bean.QueryWechatUpkeep;
import com.jy.adscm.wechat.bean.WechatRepair;
import com.jy.adscm.wechat.bean.WechatUpkeep;
import com.jy.adscm.wechat.service.WechatRepairService;
import com.jy.adscm.wechat.service.WechatUpkeepService;
import com.jy.adscm.wechat.service.WechatUpkeepService;
import com.jy.adscm.wechat.utils.RedisOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-10-10
 */
@RestController
@RequestMapping("adscm/wechat/wechatUpkeep")
public class WechatUpkeepController {
    @Autowired
    private RedisOperator redis;
    @Autowired
    WechatUpkeepService wechatUpkeepService;

    @RequestMapping("select")
    public SimpleCoreResponse select(@RequestBody QueryWechatUpkeep queryWechatUpkeep, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        queryWechatUpkeep.setOpenid(openid);
        Page<WechatUpkeep> page=new Page(queryWechatUpkeep.getCurrentPage(),queryWechatUpkeep.getPageSize());
        page= wechatUpkeepService.selectWechatUpkeep(page,queryWechatUpkeep);
        return  new SimpleCoreResponse("200","查询成功",page);
    }
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody  WechatUpkeep  wechatUpkeep, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        boolean result= wechatUpkeepService.updateWechatUpkeep(wechatUpkeep);
        return  new SimpleCoreResponse("200","修改成功",result);
    }
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody  WechatUpkeep  wechatUpkeep, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        boolean result= wechatUpkeepService.insertWechatUpkeep(wechatUpkeep,openid);
        return  new SimpleCoreResponse("200","新增成功",result);
    }
    @RequestMapping("selectById/{id}")
    public SimpleCoreResponse selectById(@PathVariable Long id, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        WechatUpkeep result= wechatUpkeepService.selectWechatUpkeepById(id);
        return  new SimpleCoreResponse("200","查询成功",result);
    }

}

